package com.leetcode.p200;

import java.util.HashMap;
import java.util.Objects;

public class Test205 {

    public boolean isIsomorphic(String s, String t) {
        if (s == null || s.isEmpty()) {
            return false;
        }

        if (s.length() != t.length()) {
            return false;
        }

        HashMap<Character, Character> char2String = new HashMap<>();
        HashMap<Character, Character> string2Char = new HashMap<>();

        for (int i = 0; i < s.length(); i++) {
            Character cChar = s.charAt(i);
            Character value = t.charAt(i);

            if ((char2String.containsKey(cChar) && !char2String.get(cChar).equals(value))
                    || (string2Char.containsKey(value) && !Objects.equals(string2Char.get(value), cChar))) {
                return false;
            }
            char2String.put(cChar, value);
            string2Char.put(value, cChar);
        }
        return true;
    }

    public static void main(String[] args) {
        Test205 test = new Test205();
//        System.out.println(test.isIsomorphic("eaa", "add"));
        System.out.println(test.isIsomorphic("foo", "bar"));
//        System.out.println(test.wordPattern("abba", "dog dog dog dog"));
    }

}
